<template>
  <div>
    <form action="/">
      <van-search
      background="#f6f5f6"
      v-model="value"
      show-action
      placeholder="请输入搜索关键词"
      @search="onSearch" @cancel="$router.go(-1)"/>
    </form>
    <van-list
  v-model="loading"
  :finished="finished"
>
  <van-cell v-for="(item,index) in list" :key="index" :title="item.communityName" @click="clickFn($event)" />
</van-list>
  </div>
</template>

<script>
import { community } from '@/api/other'
import { getStr, setStr } from '@/utils/storage'
export default {
  data () {
    return {
      value: '',
      list: [],
      finished: true,
      loading: false
    }
  },
  created () {

  },
  methods: {
    async onSearch () {
      getStr() || setStr(JSON.stringify({ label: '上海', value: 'AREA|dbf46d32-7e76-1196', pinyin: 'shanghai', short: 'sh' }))
      const res = await community({ id: JSON.parse(getStr()).value, name: this.value })
      this.list = res.body
      console.log(res.body)
    },
    clickFn (e) {
      console.log(e.target.innerText)
      this.$router.push({
        path: '/housing',
        query: {
          communityName: e.target.innerText
        }
      })
    }
  }
}
</script>

<style>
</style>
